package org.zjt.weather.demo;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * DESC   设置Dadoop传输类型 ： key
 *
 * @author
 * @create 2017-05-23 下午1:07
 **/

public class WeatherKey implements WritableComparable<WeatherKey> {
    private Integer year;
    private Integer month;

    public Double getHot() {
        return hot;
    }

    public void setHot(Double hot) {
        this.hot = hot;
    }

    private Double hot;

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }


    /**
     * 比较数据类型是否相等
     *
     * @param o
     * @return
     */
    @Override
    public int compareTo(WeatherKey o) {
        Integer var1 = Integer.compare(this.getYear(), o.getYear());
        if (var1 != 0)
            return var1;
        int var2 = Integer.compare(this.getMonth(), o.getMonth());
        if (var2 != 0)
            return var1;
        return Double.compare(this.getHot(), o.getHot());
    }

    /**
     * key的序列化传输输出 (顺序和反序列化一样)
     *
     * @param dataOutput
     * @throws IOException
     */
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(this.getYear());
        dataOutput.writeInt(this.getMonth());
        dataOutput.writeDouble(this.getHot());

    }

    /**
     * key反序列化解析 （顺序和序列化一样）
     *
     * @param dataInput
     * @throws IOException
     */
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.setYear(dataInput.readInt());
        this.setMonth(dataInput.readInt());
        this.setHot(dataInput.readDouble());
    }
}
